<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>修改DOM样式</title>
    <style>
      div {
        width: 400px;
        margin: 50px auto;
        padding: 20px;
      }
      .c1 {
        color: red;
      }
      .c2 {
        font-size: 2em;
      }
    </style>
  </head>
  <body>
    <div id="id1" style="outline: 1px solid red">
      <p class="c1 c2">一段文字</p>
      <button id="btn1">切换颜色</button>
      <button id="btn2">切换边框</button>
    </div>
    <script>
      const p = document.querySelector("p.c1.c2");
      console.log(p.className);
      //p.className = "c2";
      console.log(p.classList);
      p.classList.remove("c2");
      p.classList.add("c2");
      p.classList.toggle("c2");
      btn1.addEventListener("click", () => {
        p.classList.toggle("c1");
      });
      const div = document.getElementById("id1");
      console.log(div.style);
      const btn2 = document.getElementById("btn2");
      btn2.addEventListener("click", () => {
        if (div.style.outline) div.style.outline = "";
        else div.style.outline = "1px solid red";
      });
    </script>
  </body>
</html>
